<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>03_Proxy-其他捕获器的监听方法</title>
</head>
<body>

  <script>

    const obj = {
      name: '张三',
      age: 18
    }

    const p = new Proxy(obj, {
      // 获取属性
      get(target, key) {
        console.log('get方法被调用了')
        return target[key]
      },
      // 设置属性
      set(target, key, value) {
        console.log('set方法被调用了')
        target[key] = value
      },
      // 删除属性
      deleteProperty(target, key) {
        console.log('deleteProperty方法被调用了')
        delete target[key]
      },
      // 判断某个属性是否在对象中
      has(target, key) {
        console.log('has方法被调用了')
        return key in target
      }
    })

    console.log(p.name)
    p.name = '李四'
    console.log(p.name)
    delete p.name
    console.log(p.name)
    console.log('name' in p)
    console.log('age' in p)

    console.log(p);
    
  </script>
  
</body>
</html>